//
//  GameModel.h
//  AtmKiller
//
//  Created by USoft on 6/5/14.
//
//

#ifndef GAMEMODEL_H
#define GAMEMODEL_H

#include "cocos2d.h"
#include "../../util/include/util.h"
#include "../../listener/include/listener.h"

#include "../../model/entity/Counter.h"
#include "../../model/entity/EntityCharacter.h"
#include "../../model/entity/EntityCharacterAvatar.h"
#include "../../model/entity/EntityRepository.h"
#include "../../model/entity/FingerInformation.h"
#include "../../model/entity/FingerUpgrade.h"
#include "../../model/entity/FingerBonus.h"
#include "../../model/objectmodel/Finger.h"
#include "../../model/objectmodel/Atm.h"
#include "../../model/objectmodel/WorldObj.h"
#include "../../model/objectmodel/Coin.h"
#include "../../model/objectmodel/Character.h"
#include "../../model/objectmodel/Combo.h"
#include "../../model/objectmodel/FingerEffect.h"
#include "../../model/entity/achievement/MoneyAchievement.h"
#include "../../model/entity/achievement/LevelAchievement.h"
#include "../../model/entity/achievement/OtherAchievement.h"
#include "../../model/entity/AtmBonus.h"
#include "../../model/entity/AtmInformation.h"
#include "../sound/SoundCommand.h"
#include "../sound/SoundModel.h"

USING_NS_CC;

class GameModel: public Ref {
    UG_PROPERTY_FULL(cocos2d::Size, displayResolutionSize, DisplayResolutionSize);
    UG_PROPERTY_FULL(cocos2d::Point, vectorMove, VectorMove);
    UG_PROPERTY_GETTER(SoundModel*, soundModel, SoundModel);
    UG_PROPERTY_FULL(b2World*, world, World);
    UG_PROPERTY_FULL(BigNumber*, score, Score);
    UG_PROPERTY_FULL(Combo*, combo, Combo);
    UG_PROPERTY_FULL(int, gameState, GameState);// use to handle update func
    UG_PROPERTY_FULL(int, numberOfNoti, NumberOfNoti);
    UG_PROPERTY_FULL(int, numberOfBonusNoti, NumberOfBonusNoti);
    UG_PROPERTY_FULL(Counter*, counter,Counter);
    
    UG_PROPERTY_GETTER(__Dictionary*, attacks, Attacks);// use to save the remainTimeToAttack of each characters
    
    UG_PROPERTY_GETTER(EntityRepository*, ettRepository, EttRepository);// use to save all base information of characters
    UG_PROPERTY_GETTER(FingerInformation*, fingerInformation, FingerInformation);// use to save all information of finger
    UG_PROPERTY_GETTER(Finger*, finger, Finger);
    UG_PROPERTY_GETTER(AtmInformation*, atmInformation, AtmInformation);
    UG_PROPERTY_GETTER(Atm*, atm, Atm);
    UG_PROPERTY_GETTER(__Array*, coins, Coins);//store all coins which is fired by atm
    UG_PROPERTY_GETTER(__Array*, effects, Effects);
    UG_PROPERTY_GETTER(__Array*, listeners, Listeners);
    UG_PROPERTY_GETTER(__Array*, worldObjects, WorldObjects);
    UG_PROPERTY_GETTER(__Array*, achievements, Achievements);
    UG_PROPERTY_GETTER(__Dictionary*, characters, Characters);//store all characters corresponding with ID
    
public:
    bool isPlayGame;
    static GameModel* getInstance();
    int numOfUnlockedAchi;
    void update(float dt);
    void initialize();
    void createCoins(BigNumber *amount, int coinFrom);
    void addMoney(BigNumber* money);
    void subMoney(BigNumber* money);
    void handTouching();
    void createLand();
    void addListener(UGListener* listener);
    void effectAppear(cocos2d::Point point);
    
    void fireCoinsAppear(Coin* coin, BigNumber* amount, __Integer* id);
    void fireEffectAppear(FingerEffect* effect);
    void fireCoinsOut(Coin* coin);
    void fireCharacterAttack(Character* character);
    void fireChangeCharacter();
    void fireShowAchievementNoti(int achievementId);
    void fireChangeAvatarShopping();
    void fireUpgradeAtmFace();
    void fireShowNotification(int characterId);
    void fireRemoveNotification(int characterId);
    void fireShowBonusNotification(int characterId);
    void fireRemoveBonusNotification(int characterId);
    
    bool isAtmTouchable();
    bool isCharacterTouchable();
    BigNumber* bonusFinger(BigNumber* money);
    BigNumber* bonusAtm(BigNumber* money);
    BigNumber* achievementEffect(BigNumber* money, int effectType);
    int getTotalCharactersLevel();
    int getTotalCharactersUpgrade();
    void saveStatusAchievement();
    void loadStatusAchievement();
protected:
    float currentSaveTime;
private:
    GameModel();
    ~GameModel();
    void createWorld();
    void addToWorld(cocos2d::Point position, cocos2d::Size size, float density, float friction, float restitution, WorldObj *obj);

    void loadCharacter();
    void loadFinger();
    void loadAtm();
    void loadGame();
    void loadDefault();
    void loadCounter();
    void loadAchievement();
    void saveGame();
    void saveCounter();
    void play();
    void upgrade();
    void setComparisonAchievement();
    void examineAchievements();
};

#endif /* defined(__AtmKiller__GameModel__) */
